/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.panels;

import java.awt.Container;
import javax.swing.table.TableModel;
import model.OpstiDomenskiObjekat;
import model.dataset.Dataset;
import view.forms.OpstaEkranskaForma;
import view.guicontrollers.ControllerUI_DSExport;
import view.panels.tablemodels.TableModelDataSets;

/**
 *
 * @author Jelena
 */
public class PanelExportDS extends javax.swing.JPanel implements OpstaEkranskaForma{

    private ControllerUI_DSExport controllerExport;

    /**
     * Creates new form PanelImportDS
     */
    public PanelExportDS() {
        initComponents();
        setActivePanel(new PanelAllDataSets());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rbgColumnSeparator = new javax.swing.ButtonGroup();
        tpnlExportDS = new javax.swing.JTabbedPane();
        pnlSelectDS = new javax.swing.JPanel();
        btnNextSelect = new javax.swing.JButton();
        pnlAllDataSets = new javax.swing.JPanel();
        pnlSelectFormat = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        checkBCSV = new javax.swing.JCheckBox();
        checkBAML = new javax.swing.JCheckBox();
        chechBText = new javax.swing.JCheckBox();
        btnNextFormat = new javax.swing.JButton();
        btnPreviousFormat = new javax.swing.JButton();
        pnlSelectFile = new javax.swing.JPanel();
        fileChooserDS = new javax.swing.JFileChooser();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtFieldFileName = new javax.swing.JTextField();

        pnlSelectDS.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnNextSelect.setText("Next -->");
        btnNextSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextSelectActionPerformed(evt);
            }
        });
        pnlSelectDS.add(btnNextSelect, new org.netbeans.lib.awtextra.AbsoluteConstraints(686, 546, -1, -1));

        pnlAllDataSets.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        pnlSelectDS.add(pnlAllDataSets, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 780, 500));

        tpnlExportDS.addTab("Step 1: Select DataSet to save", pnlSelectDS);

        jLabel4.setText("Select format you want to export this data set:");

        checkBCSV.setText("CSV");

        checkBAML.setText("AML");
        checkBAML.setEnabled(false);

        chechBText.setText("Text");
        chechBText.setEnabled(false);

        btnNextFormat.setText("Next -->");
        btnNextFormat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextFormatActionPerformed(evt);
            }
        });

        btnPreviousFormat.setText("<-- Prevoius");
        btnPreviousFormat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPreviousFormatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlSelectFormatLayout = new javax.swing.GroupLayout(pnlSelectFormat);
        pnlSelectFormat.setLayout(pnlSelectFormatLayout);
        pnlSelectFormatLayout.setHorizontalGroup(
            pnlSelectFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSelectFormatLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel4)
                .addGap(33, 33, 33)
                .addGroup(pnlSelectFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(chechBText)
                    .addComponent(checkBAML)
                    .addComponent(checkBCSV))
                .addContainerGap(454, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlSelectFormatLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnPreviousFormat)
                .addGap(18, 18, 18)
                .addComponent(btnNextFormat)
                .addGap(23, 23, 23))
        );
        pnlSelectFormatLayout.setVerticalGroup(
            pnlSelectFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSelectFormatLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(pnlSelectFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(checkBCSV))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(checkBAML)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chechBText)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 453, Short.MAX_VALUE)
                .addGroup(pnlSelectFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNextFormat)
                    .addComponent(btnPreviousFormat))
                .addGap(19, 19, 19))
        );

        tpnlExportDS.addTab("Step 2: Select format", pnlSelectFormat);

        fileChooserDS.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        fileChooserDS.setCurrentDirectory(new java.io.File("C:\\Users\\Djordje\\Desktop"));
        fileChooserDS.setDialogTitle("Please select the location where the file should be exported.");
        fileChooserDS.setFileFilter(null);
        fileChooserDS.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
        fileChooserDS.setName("Directory chooser"); // NOI18N
        fileChooserDS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileChooserDSActionPerformed(evt);
            }
        });

        jLabel3.setText("Please select the file that should be imported.");

        jLabel5.setText("File name: ");

        javax.swing.GroupLayout pnlSelectFileLayout = new javax.swing.GroupLayout(pnlSelectFile);
        pnlSelectFile.setLayout(pnlSelectFileLayout);
        pnlSelectFileLayout.setHorizontalGroup(
            pnlSelectFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlSelectFileLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlSelectFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fileChooserDS, javax.swing.GroupLayout.DEFAULT_SIZE, 776, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(pnlSelectFileLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtFieldFileName, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        pnlSelectFileLayout.setVerticalGroup(
            pnlSelectFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlSelectFileLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addGroup(pnlSelectFileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtFieldFileName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(fileChooserDS, javax.swing.GroupLayout.PREFERRED_SIZE, 482, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        tpnlExportDS.addTab("Step 3:Select save location", pnlSelectFile);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tpnlExportDS))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tpnlExportDS))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void fileChooserDSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileChooserDSActionPerformed
        controllerExport.lastStep();
    }//GEN-LAST:event_fileChooserDSActionPerformed

    private void btnPreviousFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreviousFormatActionPerformed
        controllerExport.saveFildValues();
        controllerExport.disableAllExcept(0);
    }//GEN-LAST:event_btnPreviousFormatActionPerformed

    private void btnNextFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextFormatActionPerformed
        controllerExport.saveFildValues();
        controllerExport.disableAllExcept(2);
    }//GEN-LAST:event_btnNextFormatActionPerformed

    private void btnNextSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextSelectActionPerformed
        controllerExport.disableAllExcept(1);
        controllerExport.saveFildValues();
    }//GEN-LAST:event_btnNextSelectActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNextFormat;
    private javax.swing.JButton btnNextSelect;
    private javax.swing.JButton btnPreviousFormat;
    private javax.swing.JCheckBox chechBText;
    private javax.swing.JCheckBox checkBAML;
    private javax.swing.JCheckBox checkBCSV;
    private javax.swing.JFileChooser fileChooserDS;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel pnlAllDataSets;
    private javax.swing.JPanel pnlSelectDS;
    private javax.swing.JPanel pnlSelectFile;
    private javax.swing.JPanel pnlSelectFormat;
    private javax.swing.ButtonGroup rbgColumnSeparator;
    private javax.swing.JTabbedPane tpnlExportDS;
    private javax.swing.JTextField txtFieldFileName;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the fileChooserDS
     */
    public javax.swing.JFileChooser getFileChooserDS() {
        return fileChooserDS;
    }



    /**
     * @return the btnNextFormat
     */
    public javax.swing.JButton getBtnNextFormat() {
        return btnNextFormat;
    }


    /**
     * @return the btnNextSelect
     */
    public javax.swing.JButton getBtnNextSelect() {
        return btnNextSelect;
    }

    /**
     * @return the btnPreviousFormat
     */
    public javax.swing.JButton getBtnPreviousFormat() {
        return btnPreviousFormat;
    }

    /**
     * @return the chechBText
     */
    public javax.swing.JCheckBox getChechBText() {
        return chechBText;
    }

    /**
     * @return the checkBAML
     */
    public javax.swing.JCheckBox getCheckBAML() {
        return checkBAML;
    }

    /**
     * @return the checkBCSV
     */
    public javax.swing.JCheckBox getCheckBCSV() {
        return checkBCSV;
    }

    /**
     * @return the tpnlExportDS
     */
    public javax.swing.JTabbedPane getTpnlExportDS() {
        return tpnlExportDS;
    }

    /**
     * @return the txtFieldFileName
     */
    public javax.swing.JTextField getTxtFieldFileName() {
        return txtFieldFileName;
    }

    /**
     * @return the txtFieldDateFormat
     */

    /**
     * @return the controllerExport
     */
    public ControllerUI_DSExport getControllerExport() {
        return controllerExport;
    }

    /**
     * @param controllerExport the controllerExport to set
     */
    public void setControllerExport(ControllerUI_DSExport controllerExport) {
        this.controllerExport = controllerExport;
    }

    /**
     * @return the pnlTableAndFieldAttributes
     */
    public void setActivePanel(PanelAllDataSets newPanel) {
        if (panelAllDataSets != null) {
            this.remove(panelAllDataSets);
        }

        
        panelAllDataSets = newPanel;
        panelAllDataSets.setSize(getPnlAllDataSets().getSize());
        panelAllDataSets.setLocation(getPnlAllDataSets().getLocation());
        getPnlAllDataSets().add(panelAllDataSets, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 780, 500));
        
        panelAllDataSets.setVisible(true);
        validate();
        repaint();
        
    }
    
    PanelAllDataSets panelAllDataSets;

    /**
     * @return the pnlAllDataSets
     */
    public javax.swing.JPanel getPnlAllDataSets() {
        return pnlAllDataSets;
    }
    
    public PanelAllDataSets getPanelAllDataSets() {
        return panelAllDataSets;
    }

    @Override
    public TableModel vratiModel() {
       return getPanelAllDataSets().getTblDatasets().getModel();
    }

    @Override
    public Object[] vratiPocetneVrednosti() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int vratiSelektovaniRed() {
        return getPanelAllDataSets().getTblDatasets().getSelectedRow();
    }

    @Override
    public OpstiDomenskiObjekat kreirajObjekat() {
        Dataset ds=((TableModelDataSets)vratiModel()).getDataSet(vratiSelektovaniRed());
        return ds;
    }
    
    
}
